package org.water.common.conveter;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;

public class XmlDateConverter extends AbstractSingleValueConverter {

	private String dateFormat="yyyy-MM-dd HH:mm:ss";
	private SimpleDateFormat simpleDateFormat=new SimpleDateFormat();
	
	public XmlDateConverter() 
	{
	}

	public XmlDateConverter(String dateFormat) 
	{
		if(dateFormat!=null)
		{
			this.dateFormat=dateFormat;
		}
	}
	@SuppressWarnings("unchecked")
	@Override
	public boolean canConvert(Class clazz) {
		if(Date.class.isAssignableFrom(clazz))
		{
			return true;
		}
		return false;
	}

	@Override
	public Object fromString(String s) {
		return null;
	}
	@Override
	public String toString(Object obj)
    {
		simpleDateFormat.applyPattern(dateFormat);
		String dateStr="";
		dateStr=simpleDateFormat.format((Date) obj);
        return dateStr;
    }
}
